package com.ydx.Controller;

import com.ydx.entity.User;
import com.ydx.service.UserService;
import com.ydx.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    @Autowired
    private UserService userService;
    @PostMapping("/login")
    public Result login(@RequestBody User requestUser) {
        String username = requestUser.getUsername();
        int userpassword = requestUser.getUserpassword();
        User user= userService.checkUserCredentials(username,userpassword);
        System.out.println(user);
        if (user!=null) {
            System.out.println("成功登录");
            return new Result(200,user);
        } else {
            System.out.println("test");
            return new Result(400,null);
        }
    }
}
